import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CommissionSettlementApi } from '#/api/spa/commission/settlement';

import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'settlementCode',
      label: '结算编码',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入结算编码',
      },
    },
    {
      fieldName: 'staffId',
      label: '员工ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入员工ID',
      },
    },
    {
      fieldName: 'settlementPeriod',
      label: '结算周期(YYYY-MM)',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入结算周期(YYYY-MM)',
      },
    },
    {
      fieldName: 'totalCommission',
      label: '总提成金额',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入总提成金额',
      },
    },
    {
      fieldName: 'totalBonus',
      label: '总奖励金额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入总奖励金额',
      },
    },
    {
      fieldName: 'totalAmount',
      label: '结算总金额',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入结算总金额',
      },
    },
    {
      fieldName: 'recordCount',
      label: '记录数量',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入记录数量',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      /*component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },*/
    },
    {
      fieldName: 'confirmTime',
      label: '确认时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'payTime',
      label: '发放时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'paymentMethod',
      label: '支付方式',
      component: 'Input',
      componentProps: {
        placeholder: '请输入支付方式',
      },
    },
    {
      fieldName: 'paymentReference',
      label: '支付凭证',
      component: 'Input',
      componentProps: {
        placeholder: '请输入支付凭证',
      },
    },
    {
      fieldName: 'staffType',
      label: '员工类型',
      rules: 'required',
      // component: 'Select',
      // componentProps: {
      //   options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
      //   placeholder: '请选择员工类型',
      // },
    },
    {
      fieldName: 'serviceCommission',
      label: '服务类提成金额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入服务类提成金额',
      },
    },
    {
      fieldName: 'salesCommission',
      label: '销售类提成金额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入销售类提成金额',
      },
    },
    {
      fieldName: 'referralCommission',
      label: '推荐/分销类提成金额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入推荐/分销类提成金额',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'settlementCode',
      label: '结算编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入结算编码',
      },
    },
    {
      fieldName: 'staffId',
      label: '员工ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入员工ID',
      },
    },
    {
      fieldName: 'settlementPeriod',
      label: '结算周期(YYYY-MM)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入结算周期(YYYY-MM)',
      },
    },
    {
      fieldName: 'totalCommission',
      label: '总提成金额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入总提成金额',
      },
    },
    {
      fieldName: 'totalBonus',
      label: '总奖励金额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入总奖励金额',
      },
    },
    {
      fieldName: 'totalAmount',
      label: '结算总金额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入结算总金额',
      },
    },
    {
      fieldName: 'recordCount',
      label: '记录数量',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入记录数量',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      // component: 'Select',
      // componentProps: {
      //   allowClear: true,
      //   options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
      //   placeholder: '请选择状态',
      // },
    },
    {
      fieldName: 'confirmTime',
      label: '确认时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'payTime',
      label: '发放时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'paymentMethod',
      label: '支付方式',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入支付方式',
      },
    },
    {
      fieldName: 'paymentReference',
      label: '支付凭证',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入支付凭证',
      },
    },
    {
      fieldName: 'staffType',
      label: '员工类型',
      // component: 'Select',
      // componentProps: {
      //   allowClear: true,
      //   options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
      //   placeholder: '请选择员工类型',
      // },
    },
    {
      fieldName: 'serviceCommission',
      label: '服务类提成金额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入服务类提成金额',
      },
    },
    {
      fieldName: 'salesCommission',
      label: '销售类提成金额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入销售类提成金额',
      },
    },
    {
      fieldName: 'referralCommission',
      label: '推荐/分销类提成金额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入推荐/分销类提成金额',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<CommissionSettlementApi.CommissionSettlement>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
    },
    {
      field: 'settlementCode',
      title: '结算编码',
      minWidth: 120,
    },
    {
      field: 'staffId',
      title: '员工ID',
      minWidth: 120,
    },
    {
      field: 'settlementPeriod',
      title: '结算周期(YYYY-MM)',
      minWidth: 120,
    },
    {
      field: 'totalCommission',
      title: '总提成金额',
      minWidth: 120,
    },
    {
      field: 'totalBonus',
      title: '总奖励金额',
      minWidth: 120,
    },
    {
      field: 'totalAmount',
      title: '结算总金额',
      minWidth: 120,
    },
    {
      field: 'recordCount',
      title: '记录数量',
      minWidth: 120,
    },
    {
      field: 'status',
      title: '状态',
      minWidth: 120,
    },
    {
      field: 'confirmTime',
      title: '确认时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'payTime',
      title: '发放时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'paymentMethod',
      title: '支付方式',
      minWidth: 120,
    },
    {
      field: 'paymentReference',
      title: '支付凭证',
      minWidth: 120,
    },
    {
      field: 'staffType',
      title: '员工类型',
      minWidth: 120,
    },
    {
      field: 'serviceCommission',
      title: '服务类提成金额',
      minWidth: 120,
    },
    {
      field: 'salesCommission',
      title: '销售类提成金额',
      minWidth: 120,
    },
    {
      field: 'referralCommission',
      title: '推荐/分销类提成金额',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
